﻿<UserControl x:Class="CardPlay.Client.Views.GameView"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             xmlns:cal="clr-namespace:Caliburn.Micro;assembly=Caliburn.Micro" 
             xmlns:Interactivity="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity" 
             xmlns:Behaviors="clr-namespace:CardPlay.Client.Behaviors" 
             mc:Ignorable="d" d:DesignHeight="300" d:DesignWidth="300">
    <UserControl.Resources>

        <Style x:Key="PilePresenterStyle" TargetType="{x:Type ContentPresenter}">
            <Setter Property="Canvas.Left" Value="{Binding Path=Bounds.X}" />
            <Setter Property="Canvas.Top" Value="{Binding Path=Bounds.Y}" />
            <Setter Property="Width" Value="{Binding Path=Bounds.Width}" />
            <Setter Property="Height" Value="{Binding Path=Bounds.Height}" />
        </Style>

        <Style x:Key="CanvasStyle" TargetType="{x:Type ItemsControl}">
            <Setter Property="IsTabStop" Value="false" />
            <Setter Property="ItemContainerStyle" Value="{StaticResource PilePresenterStyle}" />
            
            <Setter Property="ItemsPanel">
                <Setter.Value>
                    <ItemsPanelTemplate>
                        <Canvas />
                    </ItemsPanelTemplate>
                </Setter.Value>
            </Setter>
            
            <Setter Property="ItemTemplate">
                <Setter.Value>
                    <DataTemplate>
                        <ContentControl cal:View.Model="{Binding}" VerticalContentAlignment="Stretch" HorizontalContentAlignment="Stretch" IsTabStop="False" />
                    </DataTemplate>
                </Setter.Value>
            </Setter>
        </Style>
    </UserControl.Resources>

    <Grid>
        <ScrollViewer HorizontalScrollBarVisibility="Disabled" VerticalScrollBarVisibility="Disabled" ClipToBounds="true" 
                      HorizontalContentAlignment="Center" VerticalContentAlignment="Stretch">

            <Viewbox Stretch="Uniform" VerticalAlignment="Top" >
                <Interactivity:Interaction.Behaviors>
                    <Behaviors:CanvasSizingBehavior/>
                </Interactivity:Interaction.Behaviors>

                <Grid Width="{Binding Path=Canvas.Size.Width}" Height="{Binding Path=Canvas.Size.Height}" VerticalAlignment="Top" HorizontalAlignment="Center">
                    <ItemsControl x:Name="ChildNodes" Style="{StaticResource CanvasStyle}">
                        <Interactivity:Interaction.Behaviors>
                            <Behaviors:PlayerBehavior />
                        </Interactivity:Interaction.Behaviors>
                    </ItemsControl>
                </Grid>
            </Viewbox>
        </ScrollViewer>
    </Grid>
</UserControl>
